#include <stdio.h>

int binarySearch(int *table,int n,int target){
    int l = 0,r = n-1;
    if(table[r] == target){
        return r;
    }
    if(table[l] == target){
        return l;
    }
    while(l<r){
        int mid = (l+r)/2;
        if(table[mid]==target){
            return mid;
        }else if (table[mid]>target){
            r = mid;
        }else{
            l = mid;
        }
        printf("l: %d, r: %d\n",l,r);
    }
    return -1;
}

int main(){
    int table[] = {12,28,71,146,191,300,331,500};
    int n = sizeof(table)/sizeof(table[0]);
    int target = 71;

    int index = binarySearch(table,n,target);
    if(index == -1){
        printf("Element %d not found.",target);
    }else{
        printf("The index position of element %d in the table is: %d.",target,index);
    }

    return 0;
}